<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <!--edge浏览器H5兼容设置-->
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!--360浏览器H5兼容设置-->
    <meta name="renderer" content="webkit"/>
    <title>电脑商城</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!--导入核心文件-->
    <script src="../bootstrap3/js/holder.js"></script>
    <link href="../bootstrap3/css/bootstrap.css" rel="stylesheet" type="text/css">
    <script src="../bootstrap3/jquery-1.9.1.min.js"></script>
    <script src="../bootstrap3/js/bootstrap.js"></script>
    <!-- 字体图标 -->
    <link rel="stylesheet" href="../bootstrap3/font-awesome-4.7.0/css/font-awesome.css"/>
    <link rel="stylesheet" type="text/css" href="../css/layout.css"/>
    <link rel="stylesheet" type="text/css" href="../css/top.css"/>
    <link rel="stylesheet" type="text/css" href="../css/footer.css"/>
</head>

<body>
<!--头部-->
<header class="header">
    <!--电脑商城logo-->
    <div class="row">
        <div class="col-md-3">
            <a href="index.html">
                <img src="../images/index/stumalllogo.png"/>
            </a>
        </div>
        <!--快捷选项-->
        <div class="col-md-9 top-item">
            <ul class="list-inline pull-right">
                <li><a href="orders_user.html"><span class="fa fa-file-text"></span>&nbsp;订单</a></li>
                <li class="li-split">|</li>
                <li><a href="cart_user.html"><span class="fa fa-cart-plus"></span>&nbsp;购物车</a></li>
                <li class="li-split">|</li>
                <li>
                    <!--下列列表按钮 ：管理-->
                    <div class="btn-group">
                        <button type="button" class="btn btn-link dropdown-toggle" data-toggle="dropdown">
                            <span id="top-dropdown-btn"><span class="fa fa-gears"></span>&nbsp;管理 <span
                                    class="caret"></span></span>
                        </button>
                        <ul class="dropdown-menu top-dropdown-ul" role="menu">
                            <li><a href="password.html">修改密码</a></li>
                            <li><a href="userdata.html">个人资料</a></li>
                            <li><a href="upload.html">上传头像</a></li>
                            <li><a href="address.html">收货管理 </a></li>
                            <li><a href="addressdata.html">修改地址 </a></li>
                        </ul>
                    </div>
                </li>
                <li class="li-split">|</li>
                <li><a href="login.html"><span class="fa fa-user"></span>&nbsp;登录</a></li>
            </ul>
        </div>
    </div>
</header>
<!--导航 -->
<!--分割导航和顶部-->
<!--头部结束-->
<!--导航结束-->
<div class="container">
    <div class="col-md-2">

    </div>
    <div class="col-md-10	">
        <div class="panel panel-default">

            <div class="panel-body">
                <!--修改资料表单开始-->
                <form id="form-change-info" class="form-horizontal" role="form">
                    <div class="form-group">
                        <label class="col-md-2 control-label">地址类型：</label>
                        <div class="col-md-8">
                            <input id="tag" type="text" class="form-control" value="家">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-md-2 control-label">收货人姓名:</label>
                        <div class="col-md-8">
                            <input id="name" name="name" type="text" class="form-control" placeholder="请输入收货人姓名"
                                   value="用户">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-md-2 control-label">详细地址</label>
                        <div class="col-md-8">
                            <input id="address" name="address" type="text" class="form-control" placeholder="请输入详细地址"
                                   value="北信科学四公寓507">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-md-2 control-label">电话号码：</label>
                        <div class="col-md-8">
                            <input id="phone" name="phone" type="text" class="form-control" placeholder="请输入电话号码"
                                   value="11011111510">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-offset-2 col-sm-10"><a href="address.html">返回</a> </label>
                        <div class="col-sm-offset-2 col-sm-10">
                            <input id="btn-change-info" type="button" class="btn btn-primary" value="修改"/>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    let adid = location.search.substr(5);
    console.log("xiugai");
    console.log(adid)
    //alert(adid);
    console.log();
    $("#btn-change-info").click(function (aid) {
        $.ajax({
            url: "/address/" + adid + "/change_info",
            type: "GET",
            data: $("#form-change-info").serialize(),
            dataType: "JSON",
            success: function (json) {
                console.log(json.data);
                /*alert(json.state)*/
                if (json.state == 200) {
                    alert("用户信息修改成功");
                    //修改成功后重新加载当前页面
                    location.href = "address.html";
                } else {
                    alert("用户名信息修改失败");
                }
            },
            error: function (xhr) {
                alert("用户信息修改时产生未知的异常" + xhr.message);//自动产生错误描述信息
            }
        })
    })

    /**
     * 一旦检测到当前的页面被加载就会出发ready方法 ready方法里放置ajax
     * $(document).ready(function(){
     *     //编写业务代码
     * });
     */
    $(document).ready(function () {
        $.ajax({
            url: "/address/",
            type: "GET",
            // data:$("#form-change-info").serialize(),
            dataType: "JSON",
            success: function (json) {
                if (json.state == 200) {
                    //将查询到的数据重新设置到控件中
                    //val表示给一个元素赋值，赋值到选中的元素上（#phone  一个文本框）
                    $("#tag").val(json.data.tag);
                    $("#name").val(json.data.name);
                    $("#address").val(json.data.address);
                    $("#phone").val(json.data.phone);

                } else {
                    alert("数据不存在");
                }
            },
            error: function (xhr) {
                alert("在查询用户信息时产生未知异常" + xhr.message);//自动产生错误描述信息
            }
        })
    })
</script>
</body>

</html>